package com.openbravo.pos.panels;

import java.util.List;

import javax.swing.JPanel;
import javax.swing.BoxLayout;

import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.data.ui.swing.dnd.AbstractJBeanDropPanel;
import cn.ekuma.epos.db.table.I_Product;
import com.openbravo.bean.Product;
import com.openbravo.data.basic.BasicException;
import com.openbravo.pos.base.AppLocal;

public class JDropProductByProductPanel extends JPanel {
	I_DataLogic dlSales ;
	/**
	 * Create the panel.
	 */
	public JDropProductByProductPanel(final I_DataLogic dlSales2) {
		initComponents();
		this.dlSales=dlSales2;
		add(new AbstractJBeanDropPanel<Product,Product>(){
			@Override
			public void doDropInsert(List<Product> beans) {
				try {
				for(Product p:beans){			
					dlSales2.updateByFieldWithIKeyed(p, I_Product.CATEGORY, bean.getCategoryID());
					p.setCategoryID(bean.getCategoryID());
				  }
				} catch (BasicException e) {
					e.printStackTrace();
				}
			}

			@Override
			public String readerBean(Product obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {
				
				return AppLocal.getIntString("label.prodcategory");
			}

			@Override
			public void doDropDelete(List<Product> dropList) {		
			}
			
		});
		add(new AbstractJBeanDropPanel<Product,Product>(){
			@Override
			public void doDropInsert(List<Product> beans) {
				try {
					for(Product p:beans){			
						dlSales2.updateByFieldWithIKeyed(p, I_Product.TAXCAT, bean.getTaxCategoryID());
						p.setTaxCategoryID(bean.getTaxCategoryID());
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
			}

			@Override
			public String readerBean(Product obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {		
				return AppLocal.getIntString("label.taxcategory");
			}

			@Override
			public void doDropDelete(List<Product> dropList) {
			}
		});
		add(new AbstractJBeanDropPanel<Product,Product>(){
			@Override
			public void doDropInsert(List<Product> beans) {
				try {
					for(Product p:beans){			
						dlSales2.updateByFieldWithIKeyed(p, I_Product.PRICESELL, bean.getPriceSell());
						p.setPriceSell(bean.getPriceSell());
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
			}

			@Override
			public String readerBean(Product obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {		
				return AppLocal.getIntString("label.prodpricesell");
			}

			@Override
			public void doDropDelete(List<Product> dropList) {
			}
		});
		add(new AbstractJBeanDropPanel<Product,Product>(){
			@Override
			public void doDropInsert(List<Product> beans) {
				try {
					for(Product p:beans){			
						dlSales2.updateByFieldWithIKeyed(p, I_Product.SIMILARCODE, bean.getM_sSimilarCode());
						p.setM_sSimilarCode(bean.getM_sSimilarCode());
					  }
					} catch (BasicException e) {
						e.printStackTrace();
					}
			}

			@Override
			public String readerBean(Product obj) {
				return obj.getName();
			}

			@Override
			public String getDropTypeTitle() {		
				return AppLocal.getIntString("label.product.m_similarCode");
			}

			@Override
			public void doDropDelete(List<Product> dropList) {
			}
		});
		
	}

	private void initComponents() {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	}	
	
}
